import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import axios from "axios";
import Modal from "../../components/modal";
const CarDetail = () => {
  const { id } = useParams();
  const [html, setHtml] = useState("");
  const handleCollect = () => {
    if (localStorage.getItem("token")) {
      alert("收藏成功");
    } else {
      Modal.alert({
				title: '用户未登录， 请登录！！！'
			});
    }
  };
  useEffect(() => {
    axios.get("/api/detail/" + id).then((resp) => {
      console.log(resp.data);
      setHtml(resp.data.html);
    });
  }, []);
  return (
    <div style={{ width: 800, margin: "0 auto" }}>
      <div dangerouslySetInnerHTML={{ __html: html }}></div>
      <div>
        <button onClick={() => handleCollect()}>收藏</button>
      </div>
    </div>
  );
};

export default CarDetail;
